/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bsc.war.form;

import bsc.war.test.XmlView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author luisZavaleta
 */
public class AddLang extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();

        ModelAndView mav = new ModelAndView();

        try {

            Document documentDemo = DocumentHelper.createDocument();
            XmlView xv = new XmlView(documentDemo);
            Element root = documentDemo.addElement("projects");
            Element project = root.addElement("project").addAttribute("id", "1").addAttribute("name", "project1").addAttribute("startdate", "2006,12,14");

            Element task = project.addElement("task").addAttribute("id", "1");
            task.addElement("name").addText("project task 1");
            task.addElement("est").addText("2006,12,14");
            task.addElement("duration").addText("200");
            task.addElement("percentcompleted").addText("60");

            task.addElement("predecessortasks");
            Element childtasks = task.addElement("childtasks");
            Element task2 = childtasks.addElement("task").addAttribute("id", "2");
            task2.addElement("name").addText("project task 1");
            task2.addElement("est").addText("2006,12,14");
            task2.addElement("duration").addText("100");
            task2.addElement("percentcompleted").addText("60");
            task2.addElement("predecessortasks");
            task2.addElement("childtasks");

            Element task2x = childtasks.addElement("task").addAttribute("id", "3");
            task2x.addElement("name").addText("project task X3");
            task2x.addElement("est").addText("2006,12,20");
            task2x.addElement("duration").addText("100");
            task2x.addElement("percentcompleted").addText("70");
            task2x.addElement("predecessortasks");
            task2x.addElement("childtasks");


            Element project2 = root.addElement("project").addAttribute("id", "2").addAttribute("name", "project1").addAttribute("startdate", "2006,12,20");

            Element task3 = project.addElement("task").addAttribute("id", "3");
            task3.addElement("name").addText("project task 1");
            task3.addElement("est").addText("2006,12,20");
            task3.addElement("duration").addText("100");
            task3.addElement("percentcompleted").addText("60");
            Element predecessortasks2 = task3.addElement("predecessortasks");
            Element childtasks2 = predecessortasks2.addElement("childtasks");
            Element task4 = childtasks2.addElement("task").addAttribute("id", "4");
            task4.addElement("name").addText("project task 1");
            task4.addElement("est").addText("2006,12,14");
            task4.addElement("duration").addText("100");
            task4.addElement("percentcompleted").addText("60");
            task4.addElement("predecessortasks");
            task4.addElement("childtasks");

            mav.setView(xv);
        } catch (Exception e) {
        }
        
        return mav;

    }

}
/*
 <?xml version="1.0" encoding="UTF-8"?>
<projects>
  <project id="1" name="project1" startdate="2006,12,14">
     <task id="1">
  	<name>project1 task1</name>
	<est>2006,12,14</est>
	<duration>120</duration>
    	<percentcompleted>60</percentcompleted>
	<predecessortasks></predecessortasks>
            <childtasks>
                  <task id="2">
                    <name>project1 task2</name>
              	    <est>2006,12,14</est>
        	    <duration>100</duration>
    	            <percentcompleted>20</percentcompleted>
        	    <predecessortasks></predecessortasks>
                    <childtasks></childtasks>
        	  </task>
                  <task id="6">
            	    <name>project1 task6</name>
	            <est>2006,12,15</est>
            	    <duration>90</duration>
        	    <percentcompleted>10</percentcompleted>
        	    <predecessortasks>2</predecessortasks>
                    <childtasks></childtasks>
                  </task>
            </childtasks>
     </task>
  </project>
  <project id="2" name="project2" startdate="2006,12,20">
     <task id="12">
	<name>project2 task12</name>
	<est>2006,12,20</est>
	<duration>140</duration>
	<percentcompleted>60</percentcompleted>
	<predecessortasks></predecessortasks>
        <childtasks>
            <task id="14">
	        <name>project2 task14</name>
       		<est>2006,12,20</est>
       		<duration>100</duration>
	        <percentcompleted>20</percentcompleted>
       		<predecessortasks></predecessortasks>
                <childtasks></childtasks>
        	</task>
        </childtasks>
     </task>
  </project>
</projects>


 */